﻿using full_leaf_framework.Scene;
using full_leaf_framework.Visual;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace tile_map;

public class Game1 : Game
{
    private GraphicsDeviceManager _graphics;
    private SpriteBatch _spriteBatch;

    private const int SCREEN_WIDTH = 800;
    private const int SCREEN_HEIGHT = 600;

    /// <summary>
    /// 摄像机
    /// </summary>
    public Camera camera;

    public TileMap tileMap;

    public Game1() {
        _graphics = new GraphicsDeviceManager(this)
        {
            PreferredBackBufferWidth = SCREEN_WIDTH,
            PreferredBackBufferHeight = SCREEN_HEIGHT
        };
        _graphics.ApplyChanges();
        Content.RootDirectory = "Content";
        IsMouseVisible = true;
    }

    protected override void Initialize() {
        base.Initialize();
    }

    protected override void LoadContent() {
        _spriteBatch = new SpriteBatch(GraphicsDevice);
        camera = new Camera(_spriteBatch, new Rectangle(0, 0, 800, 600), new Vector2(0, 0), new Vector2(800, 600));
        // 创建摄像机
        tileMap = new TileMap("Data/TileMap/classroom.json", Content);
    }

    protected override void Update(GameTime gameTime) {
        tileMap.Update(gameTime);
        tileMap.Draw(camera);
        base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);
        _spriteBatch.Begin();
        camera.Draw();
        _spriteBatch.End();
        base.Draw(gameTime);
    }
}
